﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.ProcessManager.Server.Process.Security;
using Sinacor.Infra.Core.ProcessManager.Server.Security;
using Sinacor.Infra.Service.Security.Services;
using Sinacor.Process.Bovespa.Alocacao.Server.Bovespa.Calendario.Calendario;
using Sinacor.Infra.Service.Common;

namespace Sinacor.Process.Bovespa.Alocacao.Server.Communication
{
    public class Calendario : BaseCommunication
    {
        #region Construtor

        public Calendario()
            : base(AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.LoginName, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.Password, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.CompanyId)
        {
        }

        #endregion

        #region Métodos Públicos

        public List<ProcessEntity.Calendario> ConsultarCalendarios()
        {
            ICalendario servico = null;
            Translator.DataContractToProcessEntity.Calendario translatorResponse = null;
            List<ProcessEntity.Calendario> retorno = null;

            try
            {
                using (ServiceInstance<ICalendario> service = new ServiceInstance<ICalendario>())
                {
                    servico = service.TryGetInstance(this.LoginName, this.Password, this.CompanyId);
                    translatorResponse = new Translator.DataContractToProcessEntity.Calendario();
                    retorno = translatorResponse.ToCalendario(servico.ConsultarCalendario());
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return retorno;
        }

        #endregion
    }
}
